package com.rc.saas.tenant.config;

import com.rc.saas.tenant.interceptor.TenantQueryInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.mybatis.spring.boot.autoconfigure.ConfigurationCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Mybatis配置类
 * Created by sven on 2019/10/4
 */
@Configuration
@MapperScan({"com.rc.saas.tenant.mapper*"})//与dao层的@Mapper二选一写上即可(主要作用是扫包)
public class MybatisConfig {
    /**
     * 注册拦截器
     * 启动项目时不会自动调用自定义拦截器的setProperties方法
     * @return
     */
    //@Bean
    //public TenantQueryInterceptor tenantQueryInterceptor() {
    //TenantQueryInterceptor interceptor = new TenantQueryInterceptor();
    //Properties properties = new Properties();
    // 可以调用properties.setProperty方法来给拦截器设置一些自定义参数
    //interceptor.setProperties(properties);
    //return interceptor;
    //}

    /**
     * 注册拦截器
     * 启动项目时不会自动调用自定义拦截器的setProperties方法
     * @return
     */
    //@Bean
    //public ConfigurationCustomizer mybatisConfigurationCustomizer() {
    //    return new ConfigurationCustomizer() {
    //        @Override
    //        public void customize(org.apache.ibatis.session.Configuration configuration) {
    //            configuration.addInterceptor(new TenantQueryInterceptor());
    //        }
    //    };
    //}
}
